#pragma once
#include <vector>
#include "Poller.h"

struct pollfd;
namespace xncc {
namespace foundation {
    class Channel;
    class PollPoller final : public Poller
    {
      public:
        PollPoller();
        ~PollPoller() override;
        PollPoller(const PollPoller&)             = delete;
        PollPoller(const PollPoller&&)            = delete;
        PollPoller& operator=(const PollPoller&)  = delete;
        PollPoller& operator=(const PollPoller&&) = delete;

        auto ioType() -> types::IO_MULTI_MODE::value override { return types::IO_MULTI_MODE::value::POLL; }
        void addChannel(const std::shared_ptr<Channel>& chnl) override;
        void removeChannel(const std::shared_ptr<Channel>& chnl) override;
        void updateChannel(const std::shared_ptr<Channel>& chnl) override;
        void loopOnce(int waitUs) override;

      private:
        using PollFdList = std::vector<struct pollfd>;
        PollFdList pollfds_;
        PollFdList validPfds_;
    };
}  // namespace foundation
}  // namespace xncc